package com.nervenets.shopping.hibernate.domain.order;

import com.nervenets.general.enumeration.Platform;
import com.nervenets.general.exception.LogicException;
import com.nervenets.general.hibernate.DomainObject;
import com.nervenets.general.utils.JodaUtils;
import com.nervenets.shopping.enumeration.OrderStatus;
import com.nervenets.shopping.enumeration.PayType;
import com.nervenets.shopping.enumeration.UserType;
import com.nervenets.shopping.enumeration.WealthType;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import lombok.experimental.SuperBuilder;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;

@EqualsAndHashCode(callSuper = true)
@Entity
@Table
@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
@SuperBuilder
public class RechargeOrder extends DomainObject {
    public final static String TRADE_NO_PREFIX = "RO";
    @ApiModelProperty(value = "创建用户类型")
    @Builder.Default
    @Column(columnDefinition = "tinyint")
    private UserType createUserType = UserType.user;
    @ApiModelProperty("支付内容描述")
    private String detail;
    @ApiModelProperty("支付金额")
    private int money;
    @ApiModelProperty("实际到账")
    private int actually;
    @ApiModelProperty("资产类型")
    @Column(columnDefinition = "tinyint")
    private WealthType wealthType;
    @ApiModelProperty("状态")
    @Column(columnDefinition = "tinyint")
    private OrderStatus orderStatus = OrderStatus.init;
    @ApiModelProperty("支付方式")
    @Column(columnDefinition = "tinyint")
    private PayType payType;
    @ApiModelProperty("来源平台")
    @Column(columnDefinition = "tinyint")
    private Platform platform;
    @ApiModelProperty("三方订单号")
    private String outTradeNo;
    @ApiModelProperty(value = "退款成功时间")
    private long refundTime;

    //其他不归档数据
    @ApiModelProperty("创建人昵称")
    @Transient
    private String createUserName;
    @ApiModelProperty("创建人头像")
    @Transient
    private String createUserAvatar;
    @ApiModelProperty("第三方支付信息")
    @Transient
    private Object thirdPayInfo;

    public String getTradeNo() {
        if (isNew()) throw new LogicException("order no saved.");
        return TRADE_NO_PREFIX + JodaUtils.getTimestamp() + getId();
    }
}
